home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Tool Chest / Text / WASTE 1.3a6 / Demo / Source / SmartScroll Stuff / SmartScroll.c next >
Encoding:
C/C++ Source or Header  |  1997-12-01  |  4.3 KB  |  164 lines  |  [TEXT/CWIE]

  1. /*
  2.  *    File:        SmartScroll.c
  3.  *
  4.  *    Contains:    Smart Scroll API glue code
  5.  *
  6.  *    Copyright:    © 1996, 1997 by Marc Moini, portions by Marc Menschenfreund,
  7.  *                Alessandro Levi Montalcini and Mark Shirley (Thanks!),
  8.  *                misc changes for "WASTE Demo" by Marco Piovanelli.
  9.  *                All rights reserved.
  10.  */
  11.  
  12. #ifndef __SMARTSCROLL__
  13. #include "SmartScroll.h"
  14. #endif
  15.  
  16. #ifndef __GESTALT__
  17. #include <Gestalt.h>
  18. #endif
  19.  
  20. #ifndef __TRAPS__
  21. #include <Traps.h>
  22. #endif
  23.  
  24. #ifndef __OSUTILS__
  25. #include <OSUtils.h>
  26. #endif
  27.  
  28. #if PRAGMA_ALIGN_SUPPORTED
  29. #pragma options align=mac68k
  30. #endif
  31.  
  32. #if PRAGMA_IMPORT_SUPPORTED
  33. #pragma import on
  34. #endif
  35.  
  36. enum
  37. {
  38.     gestaltSmartScroll = 'MMBS'
  39. };
  40.  
  41. enum
  42. {
  43.     kSetSmartScrollInfo         = 0L,
  44.     kSetSmartScrollProp            = 1L,
  45.     kGetSmartScrollProp            = 2L,
  46.     kDisposeAllSmartScrolls        = 3L
  47. };
  48.  
  49. typedef pascal void ( * SmartScrollProcPtr )
  50.     ( SInt32 selector, SInt32 * result, ControlRef theScrollBar, SInt32 param1, SInt32 param2 ) ;
  51.  
  52. enum
  53. {
  54.     uppSmartScrollProcInfo = kPascalStackBased
  55.         | STACK_ROUTINE_PARAMETER (1, SIZE_CODE(sizeof(SInt32)))
  56.         | STACK_ROUTINE_PARAMETER (2, SIZE_CODE(sizeof(SInt32 *)))
  57.         | STACK_ROUTINE_PARAMETER (3, SIZE_CODE(sizeof(ControlRef)))
  58.         | STACK_ROUTINE_PARAMETER (4, SIZE_CODE(sizeof(SInt32)))
  59.         | STACK_ROUTINE_PARAMETER (5, SIZE_CODE(sizeof(SInt32)))
  60. };
  61.  
  62. #if GENERATINGCFM
  63.     typedef UniversalProcPtr SmartScrollUPP ;
  64. #else
  65.     typedef SmartScrollProcPtr SmartScrollUPP ;
  66. #endif
  67.  
  68. typedef struct
  69. {
  70.     char                ssPrivate [ 16 ] ;
  71.     SmartScrollUPP        ssDispatch ;
  72.     FourCharCode        ssSignature ;
  73. } SmartScrollGestaltRec ;
  74.  
  75. static SmartScrollUPP sSmartScrollDispatch = nil ;
  76.  
  77. pascal void InitSmartScrollAwareApplication ( void )
  78. {
  79.     const SmartScrollGestaltRec * rec ;
  80.  
  81. #if ! ( GENERATINGCFM || SystemSevenOrLater )
  82.     if ( GetOSTrapAddress ( _Gestalt ) != GetToolTrapAddress ( _Unimplemented ) )
  83. #endif
  84.     {
  85.         if ( ( Gestalt ( gestaltSmartScroll, ( SInt32 * ) & rec ) == noErr ) &&
  86.              ( rec != nil ) &&
  87.              ( rec -> ssSignature == gestaltSmartScroll ) )
  88.         {
  89.             sSmartScrollDispatch = rec -> ssDispatch ;
  90.         }
  91.     }
  92. }
  93.  
  94. inline SInt32 __SmartScrollDispatch
  95.     (
  96.         SInt32 inSelector,
  97.         ControlRef inControl,
  98.         SInt32 inParam1,
  99.         SInt32 inParam2
  100.     )
  101. {
  102.      SInt32 result = 0L ;
  103.  
  104.     if ( sSmartScrollDispatch != nil )
  105.     {
  106. #if GENERATINGCFM
  107.         CallUniversalProc ( sSmartScrollDispatch, uppSmartScrollProcInfo, inSelector,
  108.                         & result, inControl, inParam1, inParam2 ) ;
  109. #else
  110.         sSmartScrollDispatch ( inSelector, & result, inControl, inParam1, inParam2 ) ;
  111. #endif
  112.     }
  113.  
  114.     return result ;
  115. }
  116.  
  117. /****************************************************************************************/
  118. /* Call this routine to set the Visible/Total proportion for a scrollbar. */
  119. /*  amountVisible is a 32bit value representing the size of the portion of the document that is visible now. */
  120. /*  amountTotal is a 32bit value representing the size of the whole document. */
  121. /*  these two parameters must share the same unit (pixels, lines, characters, frames, etc). */
  122.  
  123. pascal void SetSmartScrollInfo
  124.     (
  125.         ControlRef inScrollBar,
  126.         SInt32 inAmountVisible,
  127.         SInt32 inAmountTotal
  128.     )
  129. {
  130.     __SmartScrollDispatch ( kSetSmartScrollInfo, inScrollBar, inAmountVisible, inAmountTotal ) ;
  131. }
  132.  
  133. /****************************************************************************************/
  134. /* Call this routine to set the Visible/Total proportion for a scrollbar. */
  135. /*  proportion is a Fract value (32bit) representing the Visible/Total ratio */
  136. /*  This call has the exact same effect as SetSmartScrollInfo, you may use either one. */
  137.  
  138. pascal void SetSmartScrollProportion
  139.     (
  140.         ControlRef inScrollBar,
  141.         Fract inProportion
  142.     )
  143. {
  144.     __SmartScrollDispatch ( kSetSmartScrollProp, inScrollBar, inProportion, 0L ) ;
  145. }
  146.  
  147. /****************************************************************************************/
  148. /* Call this routine to get the last proportion you stored for this scrollbar. */
  149. /* the value returned will be 0 if there is an error (Smart Scroll not installed, or no value stored)  */
  150.  
  151. pascal Fract GetSmartScrollProportion ( ControlRef inScrollBar )
  152. {
  153.     return __SmartScrollDispatch ( kGetSmartScrollProp, inScrollBar, 0L, 0L ) ;
  154. }
  155.  
  156. /****************************************************************************************/
  157. /* Call this routine before your code Quits, to help SmartScroll */
  158. /* free the memory it reserved for the scrollbars in your Application. */
  159.  
  160. pascal void CloseSmartScrollAwareApplication ( void )
  161. {
  162.     __SmartScrollDispatch ( kDisposeAllSmartScrolls, nil, 0L, 0L ) ;
  163. }
  164.